package com.hsyt.pms.controller;

import com.hsyt.pms.controller.base.BaseController;
import com.hsyt.pms.security.SecurityContext;
import com.hsyt.pms.security.User;
import com.hsyt.pms.security.entity.MenuDto;
import com.hsyt.pms.security.service.FunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Collection;
import java.util.Set;

/**
 * @author 王勇琳
 * @ClassName: GatewayIndexController
 * @Description: 开放平台管理系统
 * @date 2017年7月12日 下午4:22:47
 */
@Controller
@RequestMapping("/system/gateway")
public class GatewayIndexController extends BaseController {

    @Autowired
    private FunctionService functionService;

    /**
     * 开放平台管理系统主页
     *
     * @return
     * @author 王勇琳
     * @date 2017年7月13日 上午9:39:23
     */
    @RequestMapping("/index")
    public ModelAndView index(ModelMap model) {
    	User user = SecurityContext.currentUser();
    	Set<String> authorities = SecurityContext.getAuthorities();
    	boolean isSuper = SecurityContext.hasRole("ROLE_SUPER");
    	if(user != null){
    		Collection<MenuDto> menuList = functionService.getMenuListNoType(isSuper,user.getUserId());
    		model.put("menus", menuList);
    		model.put("authorities", authorities);
    	}
        return new ModelAndView("index2", model);
    }

    @RequestMapping("/main")
    public String main() {
        return "/system/gateway/main/main";
    }
}
